/**
 * Created by asus on 2017/10/18.
 */
public class LinkedQueue<T>  {
    private int count;
    private LinearNode<T> front,rear;
    public LinkedQueue(){
        count=0;
        front=rear = null;
    }
    public boolean enqueue(T element){
        LinearNode<T> node = new LinearNode<>(element);
        if (count==0)
        front=node;
        else
            rear.setNext(node);
        rear=node;
        count++;
        return true;
    }
    public T dequeue()throws EmptyCollectionException{
        EmptyCollectionException problem = new EmptyCollectionException("problem");
        LinearNode<T> node  = new LinearNode<>();
        if (count==0)
            throw problem;
        node = front;
        front = front.getNext();
        count--;
        return node.getElement();
    }
    public T first() throws EmptyCollectionException{
        EmptyCollectionException problem = new EmptyCollectionException("problem");
        LinearNode<T> node = new LinearNode<>();
        if (count==0)
            throw problem;
        node=front;
        return node.getElement();
    }
    public boolean isEmpty(){
        if (count==0)
            return true;
        else return false;
    }
    public int size(){
        return count;
    }
}
